package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.mapper.ddMapper;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Baseinfo;
import com.gxa.pojo.Datadictionary;
import com.gxa.service.ddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author xiejinfeng
 * @create 2021-06-15 22:31
 * @descrip:
 */
@Service
public class ddServiceImpl implements ddService {

    @Autowired
    private ddMapper mapper;

    @Override
    public LayR list(MyTableParam param) {
        PageHelper.startPage(param.getPage(),param.getLimit());

        List<Datadictionary> allForList = mapper.findAllForList(param);

        PageInfo<Datadictionary> emplPageInfo = new PageInfo<>(allForList);

        return new LayR(0,"success",emplPageInfo.getList(),emplPageInfo.getTotal());
    }

    @Override
    public R deleteOne(Integer id) {
        mapper.deleteOneById(id);
        return new R(200,"删除成功");
    }

    @Override
    public R deleteAll(String[] ids) {

        mapper.deleteAll(ids);
        return new R(200,"删除成功");
    }

    @Override
    public R add(Datadictionary datadictionary) {

        datadictionary.setUpdateTime(new Timestamp(System.currentTimeMillis()));

        mapper.save(datadictionary);

        return new R(200,"添加成功");
    }

    @Override
    public R findById(Integer id) {

        Datadictionary datadictionary = mapper.findByPk(id);

        return new R(200,"success",datadictionary);
    }

    @Override
    public R edit(Datadictionary datadictionary) {

        datadictionary.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        mapper.update(datadictionary);

        return new R(200,"修改成功");
    }
}
